package org.apache.jsp.procesa;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.io.*;
import java.util.*;
import beans.BeanLugares;
import mapping.LugarInteres;
import mapping.ElementoMapa;

public final class procesabusquedalugares_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html; charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			"../error/errorpage.jsp", true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write('\n');
      out.write('\n');
      beans.BeanLugares mybean = null;
      synchronized (_jspx_page_context) {
        mybean = (beans.BeanLugares) _jspx_page_context.getAttribute("mybean", PageContext.PAGE_SCOPE);
        if (mybean == null){
          mybean = new beans.BeanLugares();
          _jspx_page_context.setAttribute("mybean", mybean, PageContext.PAGE_SCOPE);
        }
      }
      out.write('\n');
 
	String archivo = request.getParameter("archivo");

      out.write("\n");
      out.write("<script>\n");
      out.write("inicializaLugaresInteres('");
      out.print(archivo);
      out.write("');\n");
      out.write("</script>\n");
      out.write("\n");
      out.write("<div id = \"resultBusqLugares\">\n");
		
		int resultadosporpagina = 10;
		//Vemos por cual tupla hemos de comenzar la busqueda
		int inicTupla = Integer.parseInt(request.getParameter("iniciotupla"));
		String [] tipoLugaresElegidos = request.getParameterValues("tipo");	
		String nombreLugarInput =request.getParameter("nomlugar");
		List listLugares;
		List listLugaresMapa;
		mybean.conectar();
		
		listLugares = mybean.getLugares(tipoLugaresElegidos, nombreLugarInput, resultadosporpagina, inicTupla,"-1", 0);
		
		listLugaresMapa = mybean.getLugares(tipoLugaresElegidos, nombreLugarInput,"-1", 1);
		mybean.generaXMLLugares(archivo, listLugaresMapa);
		if(listLugares == null)
	       		out.println("<p><h1>ERROR</h1></p>");
		else if(!listLugares.isEmpty()){
      out.write("\n");
      out.write("\t\t<div id=\"res_busq\" class=\"res_busq\">\t\t\n");
      out.write("\t\t\t<table border=\"1\" width=\"91%\">\n");
      out.write("\t\t\t<tbody id=\"cuerpoTablaLugares\">\n");
      out.write("\t        <tr class=\"trcabeclista\">\n");
      out.write("\t            <td id=\"tdnomlugar\"><b>NOMBRE</b></td>\n");
      out.write("\t            <td id=\"tddesclugar\"><b>DESCRIPCI&Oacute;N</b></td>\n");
      out.write("\t            <td id=\"tdtipolugar\"><b>TIPO</b></td>\n");
      out.write("\t            <td class=\"tdbts\">&nbsp;</td>\n");
      out.write("\t        </tr>\n");
      out.write("\t\t\t");

				Iterator it2 = listLugares.iterator();
				while(it2.hasNext()) {
					LugarInteres li = (LugarInteres)it2.next();		
					if(li.isEs_de_interes()){
			
      out.write("\n");
      out.write("\t\t\t<!-- En esta tabla tendremos ,en una columna por fila, un input hidden donde \n");
      out.write("\t\t\tse almacenan las coordenadas asociadas a un lugar(Invisibles al usuario) -->\n");
      out.write("\t\t\t\t<tr class = \"listado\"  id=\"fila");
      out.print(li.getId_elem_mapa());
      out.write("\" onmouseover=\"iluminaFila(this)\" onmouseout=\"oscureceFila(this)\">\t\n");
      out.write("\t\t\t\t<td class=\"nombrelugar\">\n");
      out.write("\t\t\t\t\t<div>\n");
      out.write("\t\t\t\t\t\t");
      out.print(li.getNombre());
      out.write("\n");
      out.write("\t\t\t\t\t\t<a href=\"#celdaDivMapa\">\n");
      out.write("\t\t\t\t\t\t\t<span onclick = \"centraMapaEnLugar('fila");
      out.print(li.getId_elem_mapa());
      out.write("', 'coord");
      out.print(li.getId_elem_mapa());
      out.write("')\">\n");
      out.write("\t\t\t\t\t\t\t&raquo;\n");
      out.write("\t\t\t\t\t\t\t</span>\n");
      out.write("\t\t\t\t\t\t</a>\n");
      out.write("\t\t\t\t\t\n");
      out.write("\t\t\t\t\t\t<input name=\"coordenadas\" id=\"coord");
      out.print(li.getId_elem_mapa());
      out.write("\" type=\"hidden\" value=\"");
      out.print(li.getLatitud());
      out.write(',');
      out.print(li.getLongitud());
      out.write("\"/>\n");
      out.write("\t\t\t\t\t</div>\n");
      out.write("\t\t\t\t</td>\n");
      out.write("\t\t\t\t<td class=\"descrlugar\">\n");
      out.write("\t\t\t\t\t<div>\n");
      out.write("\t       \t\t\t");

		       		final int MAX_LONG_DESCR = 90; 
			       	String desc = li.getDescripcion();
			        if(desc == null || desc.trim().length()==0)
			            desc = "&nbsp;"; 
			        if(desc.length()>MAX_LONG_DESCR){
			            desc = desc.substring(0, MAX_LONG_DESCR + 1) + "..."; 
			        }
		             
      out.write("\n");
      out.write("\t                 ");
      out.print(desc);
      out.write("     \n");
      out.write("\t       \t\t\t</div>\n");
      out.write("\t       \t\t</td>\n");
      out.write("\t       \t\t<td class=\"coltipoelemmapa\">\n");
      out.write("\t       \t\t\t");
      out.print(li.getTipo_elem_mapa());
      out.write("\n");
      out.write("\t       \t\t</td>\n");
      out.write("\t       \t\t<td class=\"tdbts\">\n");
      out.write("\t       \t\t\t<button class=\"btnimg\" id=\"detallelugar ");
      out.print(li.getId_elem_mapa());
      out.write("\" title=\"Ver detalles\" onclick=\"verDetallesLugar(");
      out.print(li.getId_elem_mapa());
      out.write(")\">\n");
      out.write("\t\t\t\t\t\t<img src=\"images/web/search.png\" alt=\"Ver +\"/>\n");
      out.write("\t\t\t\t\t</button>\n");
      out.write("\t\t\t\t\t");
 if(!li.getImagenesURL().isEmpty()) { 
      out.write("\n");
      out.write("\t\t\t\t\t\t<button class=\"btnimg\" id=\"fotoslugar ");
      out.print(li.getId_elem_mapa());
      out.write("\" title=\"Ver galer&iacute;a de fotos\" onclick=\"cargaGaleria(");
      out.print(li.getId_elem_mapa());
      out.write(")\">\n");
      out.write("\t\t\t\t\t\t\t<img src=\"images/web/galeria.png\" alt=\"Ver galeria\"/>\n");
      out.write("\t\t\t\t\t\t</button>\n");
      out.write("\t\t\t\t\t");
} else { 
      out.write("\n");
      out.write("\t\t\t\t\t\t<button class=\"btnimg\" disabled=\"disabled\" title=\"Ver galeria de fotos\">\n");
      out.write("\t\t\t\t\t\t\t<img src=\"images/web/galeriadis.png\" alt=\"Ver galeria\"/>\n");
      out.write("\t\t\t\t\t\t</button>\n");
      out.write("\t\t\t\t\t");
 } 
      out.write("\t\t\t\t\t\t\n");
      out.write("\t       \t\t</td>\n");
      out.write("\t       \t</tr>\n");
      out.write("\t       \t\t");
   		
	       		}//fin if
	       	   }//fin while
		
      out.write("\n");
      out.write("\t\t</tbody>\n");
      out.write("\t\t</table>\n");
      out.write("\t\t</div>\n");
      out.write("\t\t<br/>\n");
      out.write("\t\t<div class=\"centrado\">\n");
      out.write("   \t\t ");

		if(inicTupla > 1){
		
      out.write("\n");
      out.write("    \t\t<button id=\"ant\" class=\"mybtn\" onclick=\"retrocedeCursorResultSet('lista_lugares','form_lugares','procesabusquedalugares.jsp','get',");
      out.print(resultadosporpagina);
      out.write(")\">Anterior</button>\n");
      out.write("    \t");

		}
		if(inicTupla+resultadosporpagina < mybean.contadorTuplas){
		
      out.write("\n");
      out.write("    \t\t<button id=\"sig\" class=\"mybtn\" onclick=\"adelantaCursorResultSet('lista_lugares','form_lugares','procesabusquedalugares.jsp','get',");
      out.print(resultadosporpagina);
      out.write(")\">Siguiente</button>\n");
      out.write("    \t");

		}	
		
      out.write("\n");
      out.write("   \t\t </div>\n");
      out.write("   \t");
}	else {
      out.write("\n");
      out.write("   \t\t<div class=\"centrado\"><p>No se han encontrado resultados para su b&uacute;squeda</p></div>\n");
      out.write("   \t");
} 
   	mybean.desconectar();
   	
      out.write("\n");
      out.write("</div>");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
